package followme.yaohuile.com.followme.adapter.recommend;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.lidroid.xutils.BitmapUtils;

import org.w3c.dom.Text;

import java.util.List;

import followme.yaohuile.com.followme.R;
import followme.yaohuile.com.followme.bean.recommend.ListViewData;

/**
 * Created by Administrator on 15-11-14.
 */
public class RecommendListViewAdapter extends BaseAdapter {
    private Context context;
    private List<ListViewData> list;

    public RecommendListViewAdapter(Context context, List<ListViewData> list) {
        this.context = context;
        this.list = list;
    }

    @Override
    public int getCount() {
        int ret = 0;
        if (list != null) {
            ret = list.size();
        }
        return ret;
    }

    @Override
    public Object getItem(int position) {
        return list.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        ViewHolder vh;
        if(convertView == null){
            convertView = LayoutInflater.from(context).inflate(R.layout.fragment_recommend_item_list,null);
            vh = new ViewHolder();
            vh.imageView = (ImageView) convertView.findViewById(R.id.list_item_iv);
            vh.title = (TextView) convertView.findViewById(R.id.list_item_title);
            vh.userName = (TextView) convertView.findViewById(R.id.list_item_username);
            vh.views = (TextView) convertView.findViewById(R.id.list_item_read);
            vh.replys = (TextView) convertView.findViewById(R.id.list_item_re);
            convertView.setTag(vh);
        }else{
            vh = (ViewHolder) convertView.getTag();
        }
        vh.title.setText(list.get(position).getTitle());
        vh.userName.setText(list.get(position).getUsername());
        vh.views.setText(list.get(position).getViews());
        vh.replys.setText(list.get(position).getReplys());
        BitmapUtils bitmapUtils = new BitmapUtils(context);
        bitmapUtils.display(vh.imageView,list.get(position).getPhoto());
        return convertView;
    }
    class ViewHolder{
        ImageView imageView;
        TextView title,userName,replys,views;
    }
}
